//
//  YKRecordUtil.h
//  YK_BaseTools
//
//  Created by edward on 2019/2/20.
//

#import <Foundation/Foundation.h>
@class YKRecordUtil;

// 录音质量
typedef NS_ENUM(NSUInteger, YKRecordQuality) {
    YKRecordQualityLow,
    YKRecordQualityNormal,
    YKRecordQualityHigh,
    YKRecordQualityVeryHigh,
};

NS_ASSUME_NONNULL_BEGIN

@protocol YKRecordUtilDelegate <NSObject>

@required
/// 编码失败
- (void)record:(YKRecordUtil * _Nonnull)recort withError:(NSError *)error;

/// 录音成功
- (void)record:(YKRecordUtil * _Nonnull)recort withSuccess:(NSURL *)path duration:(NSTimeInterval)duration;

@optional
/// 音量变化
- (void)record:(YKRecordUtil * _Nonnull)recort volumePercentDidChange:(CGFloat)percent;

@end

@class YKRecordUtil;

@protocol YKRecordUtilConflictDelegate <NSObject>

@required

/// 录音开始时调用，此处需要暂停其他的音频播放和录音事件
- (BOOL)recordUtil:(YKRecordUtil * _Nonnull)util handleConflictIfNeed:(void(^_Nonnull)(BOOL complete))complete;

/// 录音结束
- (void)recordUtil:(YKRecordUtil * _Nonnull)util recordDidfinish:(BOOL)complete;

@end

@interface YKRecordUtil : NSObject

- (instancetype)init NS_UNAVAILABLE;

/// 单例
+ (instancetype)sharedInstance;

/// 默认录音质量
- (BOOL)start;

/// 指定录音质量
/// @param quailty 质量
- (BOOL)startWithQuailty:(YKRecordQuality)quailty directory:(nullable NSString *)directory;

/// 保存默认质量
- (void)saveDefaultQuailty:(YKRecordQuality)quality;

/// 是否可以开启录音
- (BOOL)prepareForRecord;

/// 取消
- (void)cancel;

/// 停止
- (void)stop;

/// 暂停
- (void)pause;

/// 继续
- (void)resume;

/// 默认录音文件缓存
- (long long)recordFileSize;

/// 清理默认录音文件缓存
- (BOOL)clearRecordFileSize;

/// 是否已经授权
+ (BOOL)authorized;

/// 录音时长
@property (nonatomic, assign, readonly) NSTimeInterval voiceSize;

/// 录音文件位置
@property (nonatomic, strong, readonly) NSURL *recodingPath;

/** 当前录音质量 */
@property (nonatomic, assign, readonly) YKRecordQuality currentQuality;

/** 代理 */
@property (nonatomic, weak) id<YKRecordUtilDelegate> delegate;

/** 处理音频冲突 */
@property (nonatomic, weak) id<YKRecordUtilConflictDelegate> conflictDelegate;

@end

NS_ASSUME_NONNULL_END
